"""
Author : sunshicheng
DateTime : 2021/6/16.4:50 下午
FileName : pytest_ddt.py
Desc: pytest 显示中文名称
"""

import pytest
import requests
import time
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from unittestreport import ddt, list_data

from config.url_router import UrlRouter as ur
from config.saas_headers import saasHeaders
from model import UserAccount

token = saasHeaders('18226287291')
headers = token.test_headers()


def data_ready():
    engine = create_engine(
        'sqlite:////Users/sunshicheng/MySpace/code/QA/dailytools/data.sqlite', echo=True)
    session = sessionmaker(bind=engine)()
    response = session.query(UserAccount).filter(UserAccount.state == 1).all()
    account_list = []
    for i in response:
        account_list.append((i.account
                             , i.name))

        session.close()
    return account_list


data = data_ready()


@pytest.mark.parametrize("account,name", data)
class TestPermission(object):
    url = ur.env['test'] + ur.inter['saas']['saas_permission']

    def test_permission_get(self, account, name):
        print(name)
        data = {"account": account}
        print(data)
        response = requests.get(self.url, params=data, headers=headers)
        result = response.json()
        assert result['code'] == 0


if __name__ == '__main__':
    pytest.main(["-v", "pytest_ddt.py"])
